home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / inter52e.zip / INTLIST.E < prev    next >
Text File  |  1996-10-18  |  43KB  |  1,497 lines

  1. /****************************************************************/
  2. /*    EEL code file for editing the Interrupt List        */
  3. /*                                */
  4. /*    Written by Ralf Brown                    */
  5. /*    LastEdit:  18 Oct 96                    */
  6. /*                                */
  7. /*  This EEL file adds the following keybindings:        */
  8. /*    Shf-Alt-A add an Access: section to the current entry    */
  9. /*    Shf-Alt-B add another BUG: to the current entry           */
  10. /*    Shf-Alt-D add a Desc: section to the current entry    */
  11. /*    Sft-Alt-I add an InstallCheck: section to current entry    */
  12. /*    Shf-Alt-R add a Range: section to the current entry       */
  13. /*    Shf-Alt-S add a Size: section to the current entry    */
  14. /*    Alt-I    add an Index: section to the current entry    */
  15. /*        add another Index: line if already on Index:    */
  16. /*      Alt-N   add a new note to current entry or data struct  */
  17. /*      Alt-P   add a Program: section to the current entry     */
  18. /*      Alt-R   insert Return: at start of line                 */
  19. /*    Alt-S    insert SeeAlso: at start of line        */
  20. /*    F11    insert a blank separator line            */
  21. /*    ^F11    create Format of: header            */
  22. /*    Shf-F11    create Values for: header            */
  23. /*    Alt-F11 create Call with: header            */
  24. /*    Alt-F12 create Bitfield for: header            */
  25. /*    F12    add the interrupt number to the separator line    */
  26. /*        preceding the current entry            */
  27. /*    ^F12    jump to a specified entry            */
  28. /*                                */
  29. /*  It adds the following unbound commands:                */
  30. /*      renumber-tables                            */
  31. /*    make-distribution                    */
  32. /*                                */ 
  33. /*  Other:                            */
  34. /*    adds intlist-mode for .LST and .1ST files        */
  35. /*    switches current buffer into intlist-mode on loading    */
  36. /*      maintains a table counter which is inserted each time   */
  37. /*        a table is created in the text                */
  38. /*      performs syntax highlighting (Epsilon v7+)        */
  39. /****************************************************************/
  40.  
  41. #include "eel.h"
  42. #if EELVERSION >= 70
  43. #include "colcode.h"
  44. #endif /* Epsilon v7.0+ */
  45.  
  46. keytable intlist_tab ;            /* key table for IntList mode */
  47.  
  48. /* on repeated F12, how often to display number of entries processed */
  49. /* for fast 386, every 100; for a Pentium, at least 300 or the message */
  50. /* line will lag way behind the actual progress */
  51. #define NUMBER_INT_PROGRESS_INTERVAL 500
  52.  
  53. /*=============================================================*/
  54. /*    Global Variables                           */
  55. /*=============================================================*/
  56.  
  57. /* table headings */
  58. char str_format_of[] = "Format of " ;
  59. char str_bitfields_for[] = "Bitfields for " ;
  60.  
  61. /* section names within an entry */
  62. char size_section[] = "Size:\t" ;
  63. char access_section[] = "Access:\t" ;
  64. char return_section[] = "Return: " ;
  65. char install_section[] = "InstallCheck:\t" ;
  66. char program_section[] = "Program: " ;
  67. char desc_section[] = "Desc:\t" ;
  68. char range_section[] = "Range:\t" ;
  69. char notes_section[] = "Notes*:\t" ;
  70. char bugs_section[] = "BUGS*:\t" ;
  71. char example_section[] = "Example: " ;
  72. char seealso_section[] = "SeeAlso: " ;
  73. char index_section[] = "Index:\t" ;
  74.  
  75. #if EELVERSION >= 70
  76. char all_sections[] = "Size:|Access:|Return:|InstallCheck:|Program:|Desc:|Range:|Notes*:|BUGS*:|Example:|SeeAlso:|Index:" ;
  77. char indented_sections[] = "[\t ]*(Return|Notes*):" ;
  78. char table_headers[] = "INT |MEM |CMOS |MSR |CALL |PORT |Format |Values |Bitfields |Call " ;
  79. #endif /* Epsilon v7.0+ */
  80.  
  81. char table_ID_letters[] = "0123456789CFMPR" ;
  82.  
  83. char *(section_order[13]) ;
  84. char *(list_files[10]) ;
  85.  
  86. when_loading()
  87. {
  88.    /* list the sections of an entry in the order they should appear (if */
  89.    /* present at all) */
  90.    section_order[0] = size_section ;
  91.    section_order[1] = access_section ;
  92.    section_order[2] = return_section ;
  93.    section_order[3] = install_section ;
  94.    section_order[4] = program_section ;
  95.    section_order[5] = desc_section ;
  96.    section_order[6] = range_section ;
  97.    section_order[7] = notes_section ;
  98.    section_order[8] = bugs_section ;
  99.    section_order[9] = example_section ;
  100.    section_order[10] = seealso_section ;
  101.    section_order[11] = index_section ;
  102.    section_order[12] = NULL ;
  103.    /* list the files comprising the full interrupt list */
  104.    list_files[0] = "cmos.lst" ;
  105.    list_files[1] = "farcall.lst" ;
  106.    list_files[2] = "memory.lst" ;
  107.    list_files[3] = "ports.lst" ;
  108.    list_files[4] = "interrup.lst" ;
  109.    list_files[5] = "tables.lst" ;
  110.    list_files[6] = "msr.lst" ;
  111.    list_files[7] = "biblio.lst" ;
  112.    list_files[8] = "glossary.lst" ;
  113.    list_files[9] = NULL ;
  114. }
  115.  
  116. /*=============================================================*/
  117. /*    Buffer-specific variables                       */
  118. /*=============================================================*/
  119.  
  120. buffer spot table_counter ;
  121.  
  122. /*=============================================================*/
  123. /*=============================================================*/
  124.  
  125. int empty_line()
  126. {
  127.    return (character(point-1) == '\n' && character(point) == '\n') ;
  128. }
  129.  
  130. /*=============================================================*/
  131. /*=============================================================*/
  132.  
  133. int is_separator_line()
  134. {
  135.    return (empty_line() || parse_string(1,"--------",NULL)) ;
  136. }
  137.  
  138. /*=============================================================*/
  139. /* search in the specified direction (1 = forward, -1 = back)  */
  140. /* for the next entry separator line                   */
  141. /*=============================================================*/
  142.  
  143. int to_separator_line(dir)
  144. int dir ;
  145. {
  146.    nl_reverse() ;
  147.    return search(dir,"\n--------") ;
  148. }
  149.  
  150. /*=============================================================*/
  151. /* move to the location where the specified section of an      */
  152. /* entry begins (if present) or should begin (if not)           */
  153. /*=============================================================*/
  154.  
  155. int to_section_start(section)
  156. char *section ;
  157. {
  158.    int i, j, len ;
  159.  
  160.    for (i = 0 ; section_order[i] ; i++)
  161.       if (strcmp(section,section_order[i]) == 0)
  162.      break ;
  163.    if (section_order[i])
  164.       {
  165.       while (!is_separator_line())
  166.      {
  167.      for (j = i ; section_order[j] ; j++)
  168.         if (parse_string(1,section_order[j],NULL))
  169.            {
  170.            if ((len = parse_string(1,section,NULL)) != 0)
  171.           {
  172.           point += len ;
  173.           return 1 ;    /* section already exists */
  174.           }
  175.            return 0 ;    /* section nonexistent, but found position */
  176.            }
  177.      if (!nl_forward())
  178.         break ;
  179.      }
  180.       return 0 ;    /* section does not yet exist */
  181.       }
  182.    else
  183.       return 0 ;    /* section not found */
  184. }
  185.  
  186. /*=============================================================*/
  187. /*=============================================================*/
  188.  
  189. int make_section(section,start_entry,name)
  190. char *section, *name ;
  191. int start_entry ;
  192. {
  193.    int start = point ;
  194.  
  195.    if (start_entry)
  196.       {
  197.       if (!to_separator_line(-1))  /* find previous separator line */
  198.      {
  199.      point = start ;
  200.      say("Not in an interrupt entry") ;
  201.      return 0 ;
  202.      }
  203.       }
  204.    else
  205.       {
  206.       to_begin_line() ;
  207.       while (!empty_line() && !parse_string(1,"\n--------",NULL))
  208.      if (!nl_reverse())
  209.         break ;
  210.       }
  211.    point++ ;                 /* skip the newline */
  212.    nl_forward() ;             /* advance to first line of entry */
  213.    if (!to_section_start(section))
  214.       {
  215.       if (name)
  216.      stuff(name) ;
  217.       else
  218.      stuff(section) ;
  219.       stuff("\n") ;
  220.       point-- ;              /* back up over inserted newline */
  221.       return 1 ;
  222.       }
  223.    else
  224.       return 0 ;
  225.    return 2 ;  /* just in case */
  226. }
  227.  
  228. /*=============================================================*/
  229. /*=============================================================*/
  230.  
  231. int pluralize_section(plural)
  232. char plural ;
  233. {
  234.    point -= 3 ;
  235.    if (curchar() != plural)        /* already plural ? */
  236.       {
  237.       point++ ;
  238.       insert(plural) ;
  239.       }
  240.    nl_forward() ;
  241.    while (!is_separator_line() && parse_string(1,"[ \t]",NULL))
  242.       nl_forward() ;
  243.    stuff("\t\n") ;
  244.    point-- ;
  245. }
  246.  
  247. /*=============================================================*/
  248. /* Add "SeeAlso: " to the beginning of the current line unless */
  249. /* it is already present; in that case, insert a fresh line    */
  250. /* containing just a SeeAlso: and position the cursor at the   */
  251. /* end of the new line                           */
  252. /*=============================================================*/
  253.  
  254. command see_also() on intlist_tab[ALT('s')]
  255. {
  256.    to_begin_line() ;
  257.    if (parse_string(1,"SeeAlso: ",NULL) == 0)
  258.       stuff("SeeAlso: ") ;
  259.    else
  260.       {
  261.       nl_forward() ;
  262.       stuff("SeeAlso: \n") ;
  263.       point-- ;
  264.       }
  265. }
  266.  
  267. /*=============================================================*/
  268. /* Add a Desc: section if the current entry does not already   */
  269. /* have one; if there is already a Desc: section, move to the  */
  270. /* start of it                               */
  271. /*=============================================================*/
  272.  
  273. command access() on intlist_tab[ALT('A')]
  274. {
  275.    make_section(access_section,1,NULL) ;
  276. }
  277.  
  278. /*=============================================================*/
  279. /* Add a Desc: section if the current entry does not already   */
  280. /* have one; if there is already a Desc: section, move to the  */
  281. /* start of it                               */
  282. /*=============================================================*/
  283.  
  284. command desc() on intlist_tab[ALT('D')]
  285. {
  286.    make_section(desc_section,1,NULL) ;
  287. }
  288.  
  289. /*=============================================================*/
  290. /* Add a InstallCheck: section if the current entry does not   */
  291. /* already have one; if there is already a InstallCheck:       */
  292. /* section, move to the start of it                   */
  293. /*=============================================================*/
  294.  
  295. command instcheck() on intlist_tab[ALT('I')]
  296. {
  297.    make_section(install_section,1,NULL) ;
  298. }
  299.  
  300. /*=============================================================*/
  301. /* Add a Range: section if the current entry does not already  */
  302. /* have one; if there is already a Range: section, move to the */
  303. /* start of it                               */
  304. /*=============================================================*/
  305.  
  306. command range() on intlist_tab[ALT('R')]
  307. {
  308.    make_section(range_section,1,NULL) ;
  309. }
  310.  
  311. /*=============================================================*/
  312. /* Add a Size: section if the current entry does not already   */
  313. /* have one; if there is already a Size: section, move to the  */
  314. /* start of it                               */
  315. /*=============================================================*/
  316.  
  317. command memsize() on intlist_tab[ALT('S')]
  318. {
  319.    make_section(size_section,1,NULL) ;
  320. }
  321.  
  322. /*=============================================================*/
  323. /* Add a "Program: " section to the current entry if it does   */
  324. /* not have one; otherwise, move to the beginning of the       */
  325. /* Program: section                           */
  326. /*=============================================================*/
  327.  
  328. command program() on intlist_tab[ALT('p')]
  329. {
  330.    make_section(program_section,1,NULL) ;
  331. }
  332.  
  333. /*=============================================================*/
  334. /* Add an "Index: " section to the current entry if it does    */
  335. /* not have one; otherwise, move to the beginning of the       */
  336. /* Index: section                           */
  337. /*=============================================================*/
  338.  
  339. command add_index() on intlist_tab[ALT('i')]
  340. {
  341.    to_begin_line() ;
  342.    if (parse_string(1,"Index:",NULL))
  343.       {
  344.       while (parse_string(1,"Index:",NULL))
  345.      nl_forward() ;
  346.       stuff("Index:\t\n") ;
  347.       point-- ;
  348.       }
  349.    else
  350.       make_section(index_section,1,NULL) ;
  351. }
  352.  
  353. /*=============================================================*/
  354. /*=============================================================*/
  355.  
  356. command bug() on intlist_tab[ALT('B')]
  357. {
  358.    if (!make_section(bugs_section,1,"BUG:\t"))
  359.       pluralize_section('S') ;
  360. }
  361.  
  362. /*=============================================================*/
  363. /* Add "Note: " section to the current entry; change an        */
  364. /* existing Note: to Notes: and position at end of Note:       */
  365. /* section.                               */
  366. /*=============================================================*/
  367.  
  368. command add_note() on intlist_tab[ALT('n')]
  369. {
  370.    if (!make_section(notes_section,0,"Note:\t"))
  371.       pluralize_section('s') ;
  372. }
  373.  
  374. /*=============================================================*/
  375. /* Insert "Return: " at the beginning of the current line, if  */
  376. /* not already present                           */
  377. /*=============================================================*/
  378.  
  379. command returns() on intlist_tab[ALT('r')]
  380. {
  381.    int start = point ;
  382.    
  383.    to_begin_line() ;
  384.    if (parse_string(1,return_section,NULL) == 0)
  385.       stuff(return_section) ;
  386.    else
  387.       point = start ;
  388. }
  389.  
  390. /*=============================================================*/
  391. /* insert a line of dashes prior to the current cursor line    */
  392. /*=============================================================*/
  393.  
  394. command separator_line() on intlist_tab[FKEY(11)]
  395. {
  396.    int i ;
  397.  
  398.    to_begin_line() ;
  399.    for (i = 0 ; i < 45 ; i++)
  400.       insert('-') ;
  401.    insert('\n') ;
  402. }
  403.  
  404. /*=============================================================*/
  405. /*=============================================================*/
  406.  
  407. void insert_table_counter()
  408. {
  409.    char counter[6] ;
  410.    save_var point = *table_counter + 3 ;
  411.  
  412.    /* increment that table counter */
  413.    while (curchar() >= '0')
  414.       {
  415.       if (curchar() < '9')
  416.      {
  417.      replace(point,curchar()+1) ;
  418.      break ;
  419.      }
  420.       else
  421.      {
  422.      replace(point,'0') ;
  423.      point-- ;
  424.      }
  425.       }
  426.    restore_vars() ;
  427.    /* and now insert the incremented value at point */
  428.    stuff("(Table ") ;
  429.    grab(*table_counter,*table_counter+4,counter) ;
  430.    stuff(counter) ;
  431.    stuff(")") ;
  432. }
  433.  
  434. /*=============================================================*/
  435. /* type the name of a structure, then invoke this function     */
  436. /* to create the "Format of X:" and "Offset Size Descr" lines  */
  437. /*=============================================================*/
  438.  
  439. command structure_header() on intlist_tab[FCTRL(11)]
  440. {
  441.    int start = point ;
  442.  
  443.    to_begin_line() ;
  444.    if (parse_string(1,str_format_of,NULL) == 0)
  445.       {
  446.       stuff(str_format_of) ;
  447.       to_end_line() ;
  448.       stuff(":\nOffset\tSize\tDescription\t") ;
  449.       insert_table_counter() ;
  450.       stuff("\n 00h\t") ;
  451.       }
  452.    else
  453.       point = start ;
  454. }
  455.  
  456. /*=============================================================*/
  457. /* Turn the current line into the header for a "Values of"     */
  458. /* section                               */
  459. /*=============================================================*/
  460.  
  461. command value_header() on intlist_tab[FSHIFT(11)]
  462. {
  463.    int start = point ;
  464.    
  465.    to_begin_line() ;
  466.    if (parse_string(1,"Values for ",NULL) == 0)
  467.       {
  468.       insert_table_counter() ;
  469.       stuff("\nValues for ") ;
  470.       to_end_line() ;
  471.       stuff(":\n ") ;
  472.       }
  473.    else
  474.       point = start ;
  475. }
  476.  
  477. /*=============================================================*/
  478. /* Turn the current line into the header of a "Call with"      */
  479. /* section                               */
  480. /*=============================================================*/
  481.  
  482. command call_with_header() on intlist_tab[FALT(11)]
  483. {
  484.    int start = point ;
  485.    
  486.    to_begin_line() ;
  487.    if (parse_string(1,"Call ",NULL) == 0)
  488.       {
  489.       insert_table_counter() ;
  490.       stuff("\nCall ") ;
  491.       to_end_line() ;
  492.       if (character(point-1) != ' ')
  493.      stuff(" ") ;
  494.       stuff("with:\n") ;
  495.       }
  496.    else
  497.       point = start ;
  498. }
  499.  
  500. /*=============================================================*/
  501. /* Turn the current line into the header of a "Bitfield for"   */
  502. /* section                               */
  503. /*=============================================================*/
  504.  
  505. command bitfields_for_header() on intlist_tab[FALT(12)]
  506. {
  507.    int start = point ;
  508.    
  509.    to_begin_line() ;
  510.    if (parse_string(1,str_bitfields_for,NULL) == 0)
  511.       {
  512.       stuff(str_bitfields_for) ;
  513.       to_end_line() ;
  514.       stuff(":\nBit(s)\tDescription\t") ;
  515.       insert_table_counter() ;
  516.       stuff("\n ") ;
  517.       }
  518.    else
  519.       point = start ;
  520. }
  521.  
  522. /*=============================================================*/
  523. /*=============================================================*/
  524.  
  525. char grab_int_entry_number(func_num)
  526. char *func_num ;
  527. {
  528.    int i ;
  529.    char c ;
  530.    
  531.    point += 4 ;                /* skip the "INT " */
  532.    func_num[0] = curchar() ;        /* grab the interrupt number */
  533.    point++ ;
  534.    func_num[1] = curchar() ;
  535.    nl_forward() ;            /* skip to second line of entry */
  536.    if (parse_string(1,"[ \t]*A[LHX][ \t]=[ \t][0-9A-F][0-9A-F]+h",NULL))
  537.       {
  538.       re_search(1,"[ \t]*A") ;
  539.       c = curchar() ;
  540.       point += 4 ;            /* skip ch and " = " */
  541.       if (c != 'L')
  542.      {
  543.      grab(point,point+((c=='X')?4:2),func_num+2) ;
  544.      point += ((c=='X')?4:2) ;
  545.      func_num[(c=='H')?4:6] = '-' ;    /* grab() stuck a NUL into the string */
  546.      }
  547.       else /* c == 'L' */
  548.      {
  549.      func_num[4] = curchar() ;
  550.      point++ ;
  551.      func_num[5] = curchar() ;
  552.      point ++ ;
  553.      }
  554.       point++ ;
  555.       if (parse_string(1,"[ \t]*subfn [0-9A-F][0-9A-F]+h",NULL))
  556.      {
  557.      re_search(1,"[ \t]*subfn ") ;
  558.      func_num[6] = 'S' ;
  559.      func_num[7] = 'F' ;
  560.      for (i = 0 ; i < 4 ; i++)
  561.         {
  562.         c = curchar() ;
  563.         if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'))
  564.            {
  565.            func_num[8+i] = c ;
  566.            point++ ;
  567.            }
  568.         else
  569.            break ;
  570.         }
  571.      }
  572.       nl_forward() ;            /* skip to third line of entry */
  573.       }
  574.    if (parse_string(1,"[ \t]*[BCDES][HILPSX] = [0-9A-F][0-9A-F]+h",NULL))
  575.       {
  576.       re_search(1,"[ \t]*") ;
  577.       func_num[6] = curchar() ;
  578.       point++ ;
  579.       func_num[7] = c = curchar() ;
  580.       point += 4 ;            /* skip curchar and " = " */
  581.       if (c == 'H' || c == 'L')
  582.      {
  583.      grab(point,point+2,func_num+8) ;
  584.      func_num[10] = '-' ;        /* grab() stuck a NUL into the string */
  585.      }
  586.       else /* c == 'X' || c == 'I' || c == 'P' || c == 'S' */
  587.      grab(point,point+4,func_num+8) ;
  588.       }
  589.    return 1 ;                /* successful and have func number */
  590. }
  591.  
  592. /*=============================================================*/
  593.  
  594. char grab_cmos_entry_number(func_num)
  595. char *func_num ;
  596. {
  597.    point += 5 ;                    /* skip the "CMOS " */
  598.    func_num[0] = 'R' ;            /* mark this as a CMOS RAM entry */
  599.    grab(point,point+4,func_num+1) ;
  600.    if (func_num[3] == 'h' && func_num[4] == '-')
  601.       grab(point+4,point+6,func_num+3) ;
  602.    else
  603.       {
  604.       func_num[3] = '-' ;
  605.       func_num[4] = '-' ;
  606.       }
  607.    func_num[5] = '-' ;            /* grab() stuck a NUL into string */
  608.    return 1 ;
  609. }
  610.  
  611. /*=============================================================*/
  612.  
  613. char grab_farcall_entry_number(func_num)
  614. char *func_num ;
  615. {
  616.    point += 5 ;                /* skip the "CALL " */
  617.    func_num[0] = '@' ;            /* mark this as a far call entry */
  618.    grab(point,point+4,func_num+1) ;    /* get segment of address */
  619.    grab(point+6,point+10,func_num+5) ;    /* get offset of address */
  620.    func_num[9] = '-' ;            /* grab() stuck a NUL into string */
  621.    return 1 ;
  622. }
  623.  
  624. /*=============================================================*/
  625.  
  626. char grab_msr_entry_number(func_num)
  627. char *func_num ;
  628. {
  629.    point += 4 ;                /* skip the "MSR " */
  630.    func_num[0] = 'S' ;            /* mark this as an MSR entry */
  631.    grab(point,point+8,func_num+1) ;     /* get the MSR number */
  632.    func_num[9] = '-' ;                  /* grab() stuck a NUL into string */
  633.    return 1 ;
  634. }
  635.  
  636. /*=============================================================*/
  637.  
  638. char grab_memory_entry_number(func_num)
  639. char *func_num ;
  640. {
  641.    point += 4 ;                /* skip the "MEM " */
  642.    func_num[0] = 'M' ;                /* mark this as a memory loc entry */
  643.    grab(point,point+6,func_num+1) ;    /* get segment or high word of addr */
  644.    if (func_num[5] == 'h' && func_num[6] == ':') /* segmented address? */
  645.       grab(point+6,point+10,func_num+5) ;    /* get offset of address */
  646.    else
  647.       {
  648.       grab(point+6,point+8,func_num+7) ;/* get low word of the address */
  649.       func_num[0] = 'm' ;        /* indicate linear address */
  650.       }
  651.    func_num[9] = '-' ;            /* grab() stuck a NUL into string */
  652.    return 1 ;
  653. }
  654.  
  655. /*=============================================================*/
  656.  
  657. char grab_port_entry_number(func_num)
  658. char *func_num ;
  659. {
  660.    point += 5 ;                /* skip the "PORT " */
  661.    func_num[0] = 'P' ;            /* mark this as an I/O port entry */
  662.    grab(point,point+4,func_num+1) ;    /* get starting port number */
  663.    func_num[5] = '-' ;            /* grab() stuck a NUL into string */
  664.    if (character(point+4) == '-')
  665.       {
  666.       grab(point+5,point+9,func_num+5) ; /* get ending port number */
  667.       func_num[9] = '-' ;        /* grab() stuck a NUL into string */
  668.       }
  669.    return 1 ;
  670. }
  671.  
  672. /*=============================================================*/
  673.  
  674. char grab_entry_number(func_num)
  675. char *func_num ;
  676. {
  677.    strcpy(func_num,"------------") ;    /* 12 dashes */
  678.    point++ ;                /* go to first char of separator line */
  679.    nl_forward() ;            /* go to first line of entry */
  680.    if (parse_string(1,"INT ",NULL))    /* is it an interrupt entry? */
  681.       return grab_int_entry_number(func_num) ;
  682.    else if (parse_string(1,"CMOS ",NULL) != 0)
  683.       return grab_cmos_entry_number(func_num) ;
  684.    else if (parse_string(1,"CALL ",NULL) != 0)
  685.       return grab_farcall_entry_number(func_num) ;
  686.    else if (parse_string(1,"MEM ",NULL) != 0)
  687.       return grab_memory_entry_number(func_num) ;
  688.    else if (parse_string(1,"PORT ",NULL) != 0)
  689.       return grab_port_entry_number(func_num) ;
  690.    else if (parse_string(1,"MSR ",NULL) != 0)
  691.       return grab_msr_entry_number(func_num) ;
  692.    else
  693.       return 0 ;
  694. }
  695.  
  696. /*=============================================================*/
  697. /* Put the interrupt and function number into the separator    */
  698. /* line just above the intlist entry preceding the cursor pos  */
  699. /*=============================================================*/
  700.  
  701. int number_one_int()
  702. {
  703.    char func_num[13] ;            /* 2->int, 4->AX, 6->extra reg, NUL */
  704.    int oldpoint ;
  705.    
  706.    while (to_separator_line(-1))    /* find previous separator line */
  707.       {
  708.       oldpoint = point ;
  709.       if (grab_entry_number(func_num))    /* does it belong to an intlist entry? */
  710.      {                /*   if yes, success, else try again */
  711.      point = oldpoint + 11 ;    /* skip NL and first ten dashes */
  712.      delete(point,point+12) ;    /* replace 12 dashes by the function */
  713.      stuff(func_num) ;        /*   number and extra register */
  714.      point = oldpoint + 9 ;        /* back to category letter position */
  715.      return 1 ;
  716.      }
  717.       point = oldpoint ;
  718.       }
  719.    return 0 ;                /* if we get here, we failed */
  720. }
  721.  
  722. /*=============================================================*/
  723. /* Put the interrupt and function number into the separator    */
  724. /* line just above one or more intlist entries preceding the   */
  725. /* current cursor position, letting user know of progress      */
  726. /*=============================================================*/
  727.  
  728. command number_int() on intlist_tab[FKEY(12)]
  729. {
  730.    int i, hit_top = 0 ;
  731.    
  732.    for (i = 0 ; i < iter ; i++)
  733.       {
  734.       if (!number_one_int())
  735.      {
  736.      hit_top = 1 ;
  737.      say("No prior entry.") ;
  738.      break ;
  739.      }
  740.       if (((i+1) % NUMBER_INT_PROGRESS_INTERVAL) == 0)
  741.      say("%4d...",i+1) ;
  742.       }
  743.    if (iter > 1 && !hit_top)
  744.       say("Done.") ;
  745.    iter = 1 ;
  746. }
  747.  
  748. /*=============================================================*/
  749. /*=============================================================*/
  750.  
  751. int line_has_see_also()
  752. {
  753.    int len ;
  754.    
  755.    to_begin_line() ;
  756.    if ((len = parse_string(1,".*%([sS]ee ",NULL)) != 0)
  757.       {
  758.       point += len ;        /* go to start of cross-reference */
  759.       point += parse_string(1,"also ",NULL) ;
  760.       if (parse_string(1,"INT [0-9A-F]",NULL) ||
  761.       parse_string(1,"A[XHL] =",NULL)
  762.      )
  763.      {
  764.      point++ ;        /* move into reference */
  765.      return 1 ;
  766.      }
  767.       }
  768.    return 0 ;
  769. }
  770.  
  771. /*=============================================================*/
  772. /*=============================================================*/
  773.  
  774. int grab_int_reference(ref)
  775. char *ref ;
  776. {
  777.    int begin, start = point ;
  778.    
  779.    re_search(-1,"[, \t\n]") ;    /* backup to start of reference */
  780.    if (curchar() == '\n')    /* start of line? */
  781.       re_search(1,":[ \t]") ;    /* skip the SeeAlso: */
  782.    else if (character(point-1) == 'T' && character(point-2) == 'N')
  783.       point -= 3 ;
  784.    else
  785.       point++ ;            /* back to start of reference */
  786.    begin = point ;
  787.    re_search(1,"[,\n\"]") ;    /* find end of INT-spec */
  788.    point-- ;
  789.    if (curchar() == '\"')    /* extra string at end of INT-spec? */
  790.       {
  791.       point++ ;
  792.       re_search(1,"[\"\n]") ;    /* if yes, run to end of line or string */
  793.       }
  794.    grab(begin,point,ref) ;
  795.    point = start ;
  796.    return 0 ;
  797. }
  798.  
  799. /*=============================================================*/
  800. /*=============================================================*/
  801.  
  802. int parse_int_name(entry_name,id,extra_string)
  803. char *entry_name, *id, *extra_string ;
  804. {
  805.    int start = point ;
  806.    int i ;
  807.    char c, *last ;
  808.  
  809.    for (i = strlen(entry_name)-1 ; i >= 0 ; i--)
  810.       entry_name[i] = toupper(entry_name[i]) ;
  811.    strcpy(id,"------------") ;
  812.    if (strncmp(entry_name,"INT ",4) == 0)
  813.       {
  814.       id[0] = entry_name[4] ;
  815.       id[1] = entry_name[5] ;
  816.       entry_name += 6 ;
  817.       if (entry_name[0] == '/')
  818.      entry_name++ ;
  819.       }
  820.    else if (to_separator_line(-1))
  821.       {
  822.       id[0] = character(point+11) ;
  823.       id[1] = character(point+12) ;
  824.       }
  825.    point = start ;
  826.    c = entry_name[1] ;
  827.    if (entry_name[0] == 'A' && (c == 'X' || c == 'H' || c == 'L'))
  828.       {
  829.       entry_name += 2 ;
  830.       while (entry_name[0] == ' ' || entry_name[0] == '\t')
  831.      entry_name++ ;
  832.       if (entry_name[0] == '=')
  833.      entry_name++ ;
  834.       while (entry_name[0] == ' ' || entry_name[0] == '\t')
  835.      entry_name++ ;
  836.       if (c != 'L')
  837.      {
  838.          id[2] = entry_name[0] ;
  839.          id[3] = entry_name[1] ;
  840.      }
  841.       if (c == 'X')
  842.      {
  843.      id[4] = entry_name[2] ;
  844.      id[5] = entry_name[3] ;
  845.      entry_name += 4 ;
  846.      }
  847.       else
  848.      {
  849.      if (c == 'L')
  850.         {
  851.         id[2] = entry_name[0] ;
  852.         id[3] = entry_name[1] ;
  853.         }
  854.      entry_name += 2 ;
  855.      }
  856.       if (entry_name[0] == 'H')
  857.      entry_name++ ;
  858.       if (entry_name[0] == '/')
  859.      entry_name++ ;
  860.       }
  861.    if (index("ABCDES",entry_name[0]) && index("HILPSXF",entry_name[1]))
  862.       {
  863.       id[6] = entry_name[0] ;
  864.       c = id[7] = entry_name[1] ;
  865.       entry_name += 2 ;
  866.       while (entry_name[0] == ' ' || entry_name[0] == '\t')
  867.      entry_name++ ;
  868.       if (entry_name[0] == '=')
  869.      entry_name++ ;
  870.       while (entry_name[0] == ' ' || entry_name[0] == '\t')
  871.      entry_name++ ;
  872.       id[8] = entry_name[0] ;
  873.       id[9] = entry_name[1] ;
  874.       if (c != 'H' && c != 'L' && (c != 'F' || entry_name[2] != 'h'))
  875.      {
  876.      id[10] = entry_name[2] ;
  877.      id[11] = entry_name[3] ;
  878.      entry_name += 4 ;
  879.      }
  880.       else
  881.      entry_name += 2 ;
  882.       if (entry_name[0] == 'H')
  883.      entry_name++ ;
  884.       if (entry_name[0] == '/')
  885.      entry_name++ ;
  886.       }
  887.    if (entry_name[0] == '\"')
  888.       {
  889.       entry_name++ ;
  890.       strcpy(extra_string,entry_name) ;
  891.       last = index(extra_string,'\"') ;
  892.       if (last)
  893.      *last = '\0' ;
  894.       }
  895.    else
  896.       extra_string[0] = '\0' ;
  897.    return 0 ;
  898. }
  899.  
  900. /*=============================================================*/
  901. /*=============================================================*/
  902.  
  903. int hex2_to_int(c1,c2)
  904. char c1, c2 ;
  905. {
  906.    if (c1 >= '0' && c1 <= '9')
  907.       c1 -= '0' ;
  908.    else if (c1 >= 'A' && c1 <= 'F')
  909.       c1 = c1 - 'A' + 10 ;
  910.    else if (c1 >= 'a' && c1 <= 'f')
  911.       c1 = c1 - 'a' + 10 ;
  912.    else
  913.       return -1 ;
  914.    if (c2 >= '0' && c2 <= '9')
  915.       c2 -= '0' ;
  916.    else if (c2 >= 'A' && c2 <= 'F')
  917.       c2 = c2 - 'A' + 10 ;
  918.    else if (c2 >= 'a' && c2 <= 'f')
  919.       c2 = c2 - 'a' + 10 ;
  920.    else
  921.       return -1 ;
  922.    return 16*c1 + c2 ;
  923. }
  924.  
  925. /*=============================================================*/
  926. /*=============================================================*/
  927.  
  928. char hex_digit(val)
  929. int val ;
  930. {
  931.    if (val < 0)
  932.       return '-' ;
  933.    else
  934.       return (val > 9) ? ('A' + val - 10) : ('0' + val) ;
  935. }
  936.  
  937. /*=============================================================*/
  938. /*=============================================================*/
  939.  
  940. int scan_for_entry(entry,extra_str,first_entry)
  941. char *entry, *extra_str ;
  942. int *first_entry ;
  943. {
  944.    int bestcount = 0 ;
  945.    int bestmatch = -1 ;
  946.  
  947.    if (extra_str) extra_str = 0 ;  /* for now, to avoid compiler warning */
  948.    *first_entry = 0 ;
  949.    /* scan for the first entry for the desired interrupt number */
  950.    while (to_separator_line(1))
  951.       {
  952.       point += 2 ;
  953.       if (character(point) == entry[0] && character(point+1) == entry[1])
  954.      break ;
  955.       nl_forward() ;
  956.       }
  957.    /* now scan through the entries for the given interrupt number */
  958.    while (to_separator_line(1))
  959.       {
  960.       int i ;
  961.       char buf[14] ;
  962.       point += 2 ;
  963.       grab(point,point+12,buf) ;
  964.       if ((buf[0] != entry[0] || buf[1] != entry[1]) &&
  965.       (buf[0] != '-' && buf[1] != '-'))
  966.      break ;            /* ran out of entries... */
  967.       for (i = 2 ; i <= 12 ; i++)
  968.      {
  969.      if (buf[i] != entry[i])
  970.         break ;
  971.      }
  972.       if (i > bestcount)
  973.      {
  974.      bestcount = i ;
  975.      bestmatch = point ;
  976.      if (i > 12)
  977.         break ;            /* found an exact match */
  978.      }
  979.       nl_forward() ;
  980.       }
  981.    if (bestmatch == -1)
  982.       return 0 ;            /* we failed */
  983.    else
  984.       {
  985.       *first_entry = bestmatch ;
  986.       point = bestmatch ;        /* back to best-matching entry */
  987.       nl_forward() ;
  988.       return 1 ;            /* we were successful */
  989.       }
  990. }
  991.  
  992. /*=============================================================*/
  993. /*=============================================================*/
  994.  
  995. int goto_entry(entry_name)
  996. char *entry_name ;
  997. {
  998.    char int_id[13], extra_string[60] ;
  999.    int start = point, first_entry ;
  1000.    int int_num, curr_int ;
  1001.    char search_str[22] ;
  1002.    
  1003.    parse_int_name(entry_name,int_id,extra_string) ;
  1004.    int_num = hex2_to_int(int_id[0],int_id[1]) ;
  1005.    if (to_separator_line(-1))
  1006.       {
  1007.       if (character(point+11) == '-')
  1008.      curr_int = -1 ;
  1009.       else
  1010.      curr_int = hex2_to_int(character(point+11),character(point+12)) ;
  1011.       if (int_num <= 0)
  1012.      point = 0 ;        /* go to top of file */
  1013.       else
  1014.      {
  1015.      if (curr_int <= 0)
  1016.         point = 0 ;        /* go to top of file */
  1017.      strcpy(search_str,"--------.-") ;
  1018.      search_str[10] = hex_digit((int_num-1) / 16) ;
  1019.      search_str[11] = hex_digit((int_num-1) % 16) ;
  1020.      search_str[12] = '\0' ;
  1021.      if (!re_search( (int_num<=curr_int)?-1:1, search_str))
  1022.         {
  1023.         say("%s not found.",entry_name) ;
  1024.         iter = 1 ;
  1025.         return 0 ;
  1026.         }
  1027.      to_begin_line() ;
  1028.      }
  1029.       }
  1030.    else
  1031.       point = 0 ;
  1032.    if (!scan_for_entry(int_id,extra_string,&first_entry))
  1033.       {
  1034.       say("%s not found.",entry_name) ;
  1035.       if (first_entry)
  1036.      {
  1037.      mark = start ;
  1038.      point = first_entry ;
  1039.      }
  1040.       else
  1041.      point = start ;
  1042.       }
  1043.    if (has_arg)
  1044.      iter = 1 ;                /* don't search repeatedly */
  1045.    return 0 ;
  1046. }
  1047.  
  1048. /*=============================================================*/
  1049. /*=============================================================*/
  1050.  
  1051. command goto_int() on intlist_tab[FCTRL(12)]
  1052. {
  1053.    char entry_name[60], def_entry[60] ;
  1054.    int start = point ;
  1055.  
  1056.    to_begin_line() ;
  1057.    if (parse_string(1,"SeeAlso: ",NULL) != 0)
  1058.       {
  1059.       point += 9 ;        /* skip the SeeAlso: */
  1060.       if (point < start)    /* if we were originally to the right of     */
  1061.      point = start ;    /* current position, go back to original pos */
  1062.       grab_int_reference(def_entry) ;
  1063.       get_strdef(entry_name,"Goto Interrupt",def_entry) ;
  1064.       }
  1065.    else if (line_has_see_also())
  1066.       {
  1067.       grab_int_reference(def_entry) ;
  1068.       get_strdef(entry_name,"Goto Interrupt",def_entry) ;
  1069.       }
  1070.    else
  1071.       get_string(entry_name,"Goto Interrupt: ") ;
  1072.    point = start ;
  1073.    goto_entry(entry_name) ;
  1074.    if (has_arg)
  1075.       iter = 1 ;
  1076. }
  1077.  
  1078. /*=============================================================*/
  1079. /*=============================================================*/
  1080.  
  1081. void maybe_append_table_number()
  1082. {
  1083.    if (parse_string(1,".*\t%(Table ",0) == 0)
  1084.       {
  1085.       int matchsize ;
  1086.       /* if the pattern didn't match, there is no table number, */
  1087.       /* so add it */
  1088.       to_end_line() ;
  1089.       matchsize = parse_string(-1,"[ \t]+",0) ;
  1090.       if (matchsize)
  1091.      delete(point-matchsize,point) ;
  1092.       stuff("\t") ;
  1093.       insert_table_counter() ;
  1094.       }
  1095. }
  1096.  
  1097. /*=============================================================*/
  1098. /*=============================================================*/
  1099.  
  1100. void fix_unnumbered_tables()
  1101. {
  1102.    spot start = alloc_spot(1) ;
  1103.    
  1104.    *start = point ;
  1105.    point = 0 ;
  1106.    while (search(1,"\n\n"))
  1107.       {
  1108.       switch(curchar())
  1109.      {
  1110.      case 'C':
  1111.         if (parse_string(1,"Call ") != 0)
  1112.            {
  1113.            /* we got Call..., we know it doesn't have a table number */
  1114.            insert_table_counter() ;
  1115.            stuff("\n") ;
  1116.            }
  1117.         break ;
  1118.      case 'V':
  1119.         if (parse_string(1,"Values ") != 0)
  1120.            {
  1121.            /* we know this Values... doesn't have a table number */
  1122.            insert_table_counter() ;
  1123.            stuff("\n") ;
  1124.            }
  1125.         break ;
  1126.      case 'B':
  1127.         if (parse_string(1,"Bitfields ",0) == 0)
  1128.            break ;
  1129.         nl_forward() ;    /* skip to start of next line */
  1130.         maybe_append_table_number() ;
  1131.         break ;
  1132.      case 'F':
  1133.         if (parse_string(1,"Format ",0) == 0)
  1134.            break ;
  1135.         nl_forward() ;    /* skip to start of next line */
  1136.         maybe_append_table_number() ;
  1137.         break ;
  1138.      default:
  1139.         /* not a table header, so ignore it */
  1140.         break ;
  1141.      }
  1142.       }
  1143.    point = *start ;
  1144.    free_spot(start) ;
  1145. }
  1146.  
  1147. /*=============================================================*/
  1148. /*=============================================================*/
  1149.  
  1150. short *gather_table_numbers(new_numbers)
  1151. short *new_numbers ;
  1152. {
  1153.    int tcount[6] ;
  1154.    char counter[5] ;
  1155.    int old_number ;
  1156.    int table_type ;
  1157.    spot start = alloc_spot(1) ;
  1158.    save_var case_fold = 0 ;
  1159.    
  1160.    tcount[0] = tcount[1] = tcount[2] = tcount[3] = tcount[4] = tcount[5] = 0 ;
  1161.    *start = point ;
  1162.    point = 0 ;
  1163.    while (search(1,"(Table "))
  1164.       {
  1165.       char *tbl ;
  1166.       int table_offset ;
  1167.       grab(point,point+4,counter) ;
  1168.       tbl = index(table_ID_letters,counter[0]) ;
  1169.       if (tbl)
  1170.      table_offset = (tbl-table_ID_letters) ;
  1171.       else
  1172.      table_offset = 0 ;
  1173.       old_number = strtoi(counter+1,10) + 1000*table_offset ;
  1174.       table_type = (table_offset > 9) ? (table_offset-9) : 0 ;
  1175.       new_numbers[old_number] = (short)++(tcount[table_type]) ;
  1176.       }
  1177.    point = *start ;
  1178.    free_spot(start) ;
  1179.    return new_numbers ;
  1180. }
  1181.  
  1182. /*=============================================================*/
  1183. /*=============================================================*/
  1184.  
  1185. int adjust_table_numbers(new_numbers, dangling)
  1186. short *new_numbers ;
  1187. int dangling ;
  1188. {
  1189.    char counter[5] ;
  1190.    int old_number ;
  1191.    int old_type ;
  1192.    char *tbl ;
  1193.    int table_offset ;
  1194.    spot start = alloc_spot(1) ;
  1195.    
  1196.    *start = point ;
  1197.    point = 0 ;
  1198.    while (search(1,"(Table "))
  1199.       {
  1200.       grab(point,point+4,counter) ;
  1201.       tbl = index(table_ID_letters,counter[0]) ;
  1202.       if (tbl)
  1203.      table_offset = 1000*(tbl-table_ID_letters) ;
  1204.       else
  1205.      table_offset = 0 ;
  1206.       old_number = strtoi(counter+1,10) + table_offset ;
  1207.       old_type = (counter[0] >= '0' && counter[0] <= '9') ? 0 : counter[0] ;
  1208.       if (old_number > 0)
  1209.      {
  1210.      delete(point,point+4) ;
  1211.      if (old_type)
  1212.         bprintf("%c%03d",old_type,new_numbers[old_number]%1000) ;
  1213.      else
  1214.         bprintf("%04d",new_numbers[old_number]) ;
  1215.      }
  1216.       }
  1217.    point = 0 ;
  1218.    while (re_search(1,"[, \t]%#[0-9CFMPR][0-9][0-9][0-9]"))
  1219.       {
  1220.       grab(point-4,point,counter) ;
  1221.       tbl = index(table_ID_letters,counter[0]) ;
  1222.       if (tbl)
  1223.      table_offset = 1000*(tbl-table_ID_letters) ;
  1224.       else
  1225.      table_offset = 0 ;
  1226.       old_number = strtoi(counter+1,10) + table_offset ;
  1227.       old_type = (counter[0] >= '0' && counter[0] <= '9') ? 0 : counter[0] ;
  1228.       if (old_number > 0)
  1229.      {
  1230.      if (new_numbers[old_number])
  1231.         {
  1232.         delete(point-4,point) ;
  1233.         if (old_type)
  1234.            bprintf("%c%03d",old_type,new_numbers[old_number]) ;
  1235.         else
  1236.            bprintf("%04d",new_numbers[old_number]) ;
  1237.         }
  1238.      else /* dangling xref */
  1239.         {
  1240.         dangling++ ;
  1241.         point -= 4 ;
  1242.         stuff("?") ;
  1243.         point += 4 ;
  1244.         }
  1245.      }
  1246.       }
  1247.    point = *start ;
  1248.    free_spot(start) ;
  1249.    return dangling ;
  1250. }
  1251.  
  1252. /*=============================================================*/
  1253. /*=============================================================*/
  1254.  
  1255. int get_list_file(list_file)
  1256. char *list_file ;
  1257. {
  1258.    char abs_filename[FNAMELEN] ;
  1259.    strcpy(abs_filename,list_file) ;
  1260.    absolute(abs_filename) ;
  1261.    return find_it(abs_filename,1) ;
  1262. }
  1263.  
  1264. /*=============================================================*/
  1265. /*=============================================================*/
  1266.  
  1267. command renumber_tables()
  1268. {
  1269.    short *new_numbers ;
  1270.    int num_tables ;
  1271.    int dangling ;
  1272.    int i ;
  1273.    
  1274.    for (i = 0 ; list_files[i] ; i++)
  1275.       {
  1276.       if (get_list_file(list_files[i]) == 0)
  1277.      {
  1278.      say("Renumber Pass 1: numbering unnumbered tables (%s)",
  1279.          list_files[i]) ;
  1280.      fix_unnumbered_tables() ;
  1281.      }
  1282.       else
  1283.      say("Renumber Pass 1: forced to skip %s") ;
  1284.       }
  1285.    num_tables = 1000*strlen(table_ID_letters) ;
  1286.    new_numbers = (short*)malloc(num_tables*sizeof(short)) ;
  1287.    if (!new_numbers)
  1288.       {
  1289.       say("Out of memory!") ;
  1290.       return ;
  1291.       }
  1292.    for (i = 0 ; i < num_tables ; i++)
  1293.       new_numbers[i] = 0 ;
  1294.    for (i = 0 ; list_files[i] ; i++)
  1295.       {
  1296.       if (get_list_file(list_files[i]) == 0)
  1297.      {
  1298.      say("Renumber Pass 2: gathering table numbers (%s)",
  1299.          list_files[i]) ;
  1300.      gather_table_numbers(new_numbers) ;
  1301.      }
  1302.       else
  1303.      say("Renumber Pass 2: forced to skip %s") ;
  1304.       }
  1305.    dangling = 0 ;
  1306.    for (i = 0 ; list_files[i] ; i++)
  1307.       {
  1308.       if (get_list_file(list_files[i]) == 0)
  1309.      {
  1310.      say("Renumber Pass 3: adjusting table numbers (%s)",
  1311.          list_files[i]) ;
  1312.      dangling = adjust_table_numbers(new_numbers,dangling) ;
  1313.      }
  1314.       else
  1315.      say("Renumber Pass 3: forced to skip %s") ;
  1316.       }
  1317.    free(new_numbers) ;
  1318.    if (dangling)
  1319.       say("%d dangling cross-references, search for '#?'",dangling) ;
  1320.    else
  1321.       say("Done") ;
  1322. }
  1323.  
  1324. /*=============================================================*/
  1325. /*=============================================================*/
  1326.  
  1327. command make_distribution()
  1328. {
  1329.    int i ;
  1330.    
  1331.    for (i = 0 ; list_files[i] ; i++)
  1332.       {
  1333.       /* switch to proper buffer, or load if not yet in a buffer */
  1334.       if (get_list_file(list_files[i]) == 0)
  1335.      {
  1336.      say("Setting divider lines (%s)",list_files[i]) ;
  1337.      point = size() ;
  1338.      while (point > 0)
  1339.         if (!number_one_int())
  1340.            break ;
  1341.      }
  1342.       else
  1343.      say("Forced to skip %s !",list_files[i]) ;
  1344.       }
  1345.    for (i = 0 ; list_files[i] ; i++)
  1346.       {
  1347.       /* switch to proper buffer, or load if not yet in a buffer */
  1348.       if (get_list_file(list_files[i]) == 0)
  1349.      {
  1350.      say("Tabifying file (%s)",list_files[i]) ;
  1351.      mark = 0 ;
  1352.      point = size() ;
  1353.      tabify_region() ;
  1354.      }
  1355.       }
  1356.    renumber_tables() ;
  1357.    save_all_buffers() ;
  1358.    say("Ready for distribution") ;
  1359.    point = 0 ;
  1360.    /* !!! should also split main list automatically */
  1361. }
  1362.  
  1363. /*=============================================================*/
  1364. /*=============================================================*/
  1365.  
  1366. void find_table_counter()
  1367. {
  1368.    save_var point = (size() > 10000) ? size() - 10000 : 0 ;
  1369.  
  1370.    search(1,"Highest Table Number = ") ;
  1371.    table_counter = alloc_spot(1) ;
  1372. }
  1373.  
  1374. /*=============================================================*/
  1375. /*  Coloring functions for Epsilon v7.0+               */
  1376. /*=============================================================*/
  1377.  
  1378. #if EELVERSION >= 70
  1379. int int_recolor_range(from, to)
  1380. int from, to ;
  1381. {
  1382.    if (from >= to)
  1383.       return to ;
  1384.    save_var point, matchstart, matchend ;
  1385.    set_character_color(from,to,-1) ;
  1386.    point = from ;
  1387.    if (to > size())
  1388.       to = size() ;
  1389.    while (point < to)
  1390.       {
  1391.       int start = point ;
  1392.       int len ;
  1393.       if (curchar() >= 'A' && curchar() <= 'Z')
  1394.      {
  1395.      if (parse_string(1,table_headers,NULL) != 0)
  1396.         {
  1397.         nl_forward() ;
  1398.         point-- ;
  1399.         set_character_color(start,point,color_class c_comment) ;
  1400.         }
  1401.      else if ((len = parse_string(1,all_sections,NULL)) > 0)
  1402.         set_character_color(start,start+len,color_class c_function) ;
  1403.      }
  1404.       else if (curchar() == '\t' &&
  1405.            (len = parse_string(1,indented_sections,NULL)) != 0)
  1406.      {
  1407.      while (curchar() == '\t')
  1408.         {
  1409.         point++ ;
  1410.         len-- ;
  1411.         }
  1412.      set_character_color(point,point+len,color_class c_function) ;
  1413.      }
  1414.       nl_forward() ;
  1415.       }
  1416.    return point ;
  1417. }
  1418. #endif /* Epsilon v7.0+ */
  1419.  
  1420. #if EELVERSION >= 70
  1421. int int_recolor_from_here(safe)
  1422. int safe ;
  1423. {
  1424.    if (safe == 0 || character(safe) == '\n')
  1425.       return safe ;
  1426.    nl_reverse() ;            /* start of a line is always 'safe' */
  1427.    to_begin_line() ;
  1428.    return point ;
  1429. }
  1430. #endif /* Epsilon v7.0+ */
  1431.  
  1432. /*=============================================================*/
  1433. /* Put the current buffer into IntList major mode           */
  1434. /*=============================================================*/
  1435.  
  1436. command intlist_mode()
  1437. {
  1438.    mode_keys = intlist_tab ;
  1439.    intlist_tab[')'] = intlist_tab[']'] = (short) show_matching_delimiter;
  1440.    delete_hacking_tabs = 0 ;
  1441.    major_mode = strsave("IntList") ;
  1442.    auto_indent = 0 ;
  1443.    margin_right = 79 ;
  1444.    want_backups = 1 ;
  1445.    undo_size = 100000 ;     /* less than default 500,000 since list is so big */
  1446.    find_table_counter() ;
  1447. #if EELVERSION >= 70
  1448.    recolor_range = int_recolor_range ;
  1449.    recolor_from_here = int_recolor_from_here ;
  1450.    if (want_code_coloring)
  1451.       when_setting_want_code_coloring() ;
  1452. #endif /* Epsilon v7.0+ */
  1453.    make_mode() ;
  1454. }
  1455.  
  1456. when_loading()
  1457. {
  1458.    char *curbuf ;
  1459.    int i ;
  1460.    
  1461.    want_backups = want_backups.default = 1 ;
  1462.    strcpy(backup_name,"%pbak/%b%e") ;        /* put backups in BAK subdir */
  1463.    one_window() ;
  1464.    intlist_mode() ;
  1465.    if (exist("interrup.1st"))
  1466.       {
  1467.       curbuf = bufname ;
  1468.       bufname = "interrup.1st" ;
  1469.       intlist_mode() ;
  1470.       bufname = curbuf ;
  1471.       }
  1472.    for (i = 0 ; list_files[i] ; i++)
  1473.       {
  1474.       if (exist(list_files[i]))
  1475.      {
  1476.      curbuf = bufname ;
  1477.      bufname = list_files[i] ;
  1478.      intlist_mode() ;
  1479.      bufname = curbuf ;
  1480.      }
  1481.       }
  1482. #if EELVERSION >= 70
  1483.    strcpy(mode_end," %d%p%S%>C%c") ;
  1484. #endif /* Epsilon v7.0+ */
  1485. #if EELVERSION >= 60 && EELVERSION < 70
  1486.    strcpy(mode_end," %d%p%S") ;
  1487. #endif /* Epsilon v6.x */
  1488. }
  1489.  
  1490. /*=============================================================*/
  1491. /* automagically switch into interrupt list mode on .LST and .1ST files */
  1492.  
  1493. suffix_lst()   { intlist_mode(); }
  1494. suffix_1st()   { intlist_mode(); }
  1495.  
  1496. /* end of file intlist.e */
  1497.